{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T02:30:55.324565Z",
     "start_time": "2019-10-28T02:30:51.694277Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os\n",
    "os.chdir(r'D:\\Pandas')\n",
    "pd.options.display.max_columns = 10\n",
    "pd.options.display.max_rows = 10"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.选取多个DataFrame列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:43:28.277220Z",
     "start_time": "2019-10-24T01:43:28.248295Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>city</th>\n",
       "      <th>num</th>\n",
       "      <th>riqi</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>青岛市</td>\n",
       "      <td>24</td>\n",
       "      <td>20191005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>青岛市</td>\n",
       "      <td>1</td>\n",
       "      <td>20190910</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>合肥市</td>\n",
       "      <td>24</td>\n",
       "      <td>20191007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>青岛市</td>\n",
       "      <td>4</td>\n",
       "      <td>20190909</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>合肥市</td>\n",
       "      <td>187</td>\n",
       "      <td>20191001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>479</th>\n",
       "      <td>合肥市</td>\n",
       "      <td>2</td>\n",
       "      <td>20190902</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>480</th>\n",
       "      <td>合肥市</td>\n",
       "      <td>105</td>\n",
       "      <td>20190902</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>481</th>\n",
       "      <td>合肥市</td>\n",
       "      <td>11</td>\n",
       "      <td>20190925</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>482</th>\n",
       "      <td>青岛市</td>\n",
       "      <td>10</td>\n",
       "      <td>20190913</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>483</th>\n",
       "      <td>合肥市</td>\n",
       "      <td>1</td>\n",
       "      <td>20190925</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>484 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    city  num      riqi\n",
       "0    青岛市   24  20191005\n",
       "1    青岛市    1  20190910\n",
       "2    合肥市   24  20191007\n",
       "3    青岛市    4  20190909\n",
       "4    合肥市  187  20191001\n",
       "..   ...  ...       ...\n",
       "479  合肥市    2  20190902\n",
       "480  合肥市  105  20190902\n",
       "481  合肥市   11  20190925\n",
       "482  青岛市   10  20190913\n",
       "483  合肥市    1  20190925\n",
       "\n",
       "[484 rows x 3 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用列表选取多个列\n",
    "dt = pd.read_csv('test.csv')\n",
    "dt[['city','num','riqi']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:43:52.268071Z",
     "start_time": "2019-10-24T01:43:52.259083Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    青岛市\n",
       "1    青岛市\n",
       "2    合肥市\n",
       "3    青岛市\n",
       "4    合肥市\n",
       "Name: city, dtype: object"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取单列\n",
    "dt['city'].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 更多\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:45:11.234880Z",
     "start_time": "2019-10-24T01:45:11.215926Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>city</th>\n",
       "      <th>num</th>\n",
       "      <th>riqi</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>青岛市</td>\n",
       "      <td>24</td>\n",
       "      <td>20191005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>青岛市</td>\n",
       "      <td>1</td>\n",
       "      <td>20190910</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>合肥市</td>\n",
       "      <td>24</td>\n",
       "      <td>20191007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>青岛市</td>\n",
       "      <td>4</td>\n",
       "      <td>20190909</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>合肥市</td>\n",
       "      <td>187</td>\n",
       "      <td>20191001</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  city  num      riqi\n",
       "0  青岛市   24  20191005\n",
       "1  青岛市    1  20190910\n",
       "2  合肥市   24  20191007\n",
       "3  青岛市    4  20190909\n",
       "4  合肥市  187  20191001"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将列表赋值给一个变量，便于多选\n",
    "cols = ['city','num','riqi']\n",
    "dt[cols].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:48:09.592053Z",
     "start_time": "2019-10-24T01:48:09.584082Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int64     4\n",
       "object    2\n",
       "dtype: int64"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt.get_dtype_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:48:46.157267Z",
     "start_time": "2019-10-24T01:48:46.143307Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>记录数</th>\n",
       "      <th>city</th>\n",
       "      <th>credit_by</th>\n",
       "      <th>num</th>\n",
       "      <th>num_1</th>\n",
       "      <th>riqi</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>青岛市</td>\n",
       "      <td>HUABEI</td>\n",
       "      <td>24</td>\n",
       "      <td>132</td>\n",
       "      <td>20191005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>青岛市</td>\n",
       "      <td>YUEBAO</td>\n",
       "      <td>1</td>\n",
       "      <td>87</td>\n",
       "      <td>20190910</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>YUANDONGRONGZU</td>\n",
       "      <td>24</td>\n",
       "      <td>272</td>\n",
       "      <td>20191007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>青岛市</td>\n",
       "      <td>TIANCHENGRONGZU</td>\n",
       "      <td>4</td>\n",
       "      <td>68</td>\n",
       "      <td>20190909</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>HUABEI</td>\n",
       "      <td>187</td>\n",
       "      <td>250</td>\n",
       "      <td>20191001</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   记录数 city        credit_by  num  num_1      riqi\n",
       "0    1  青岛市           HUABEI   24    132  20191005\n",
       "1    1  青岛市           YUEBAO    1     87  20190910\n",
       "2    1  合肥市   YUANDONGRONGZU   24    272  20191007\n",
       "3    1  青岛市  TIANCHENGRONGZU    4     68  20190909\n",
       "4    1  合肥市           HUABEI  187    250  20191001"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:50:21.543177Z",
     "start_time": "2019-10-24T01:50:21.528215Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>记录数</th>\n",
       "      <th>num</th>\n",
       "      <th>num_1</th>\n",
       "      <th>riqi</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>132</td>\n",
       "      <td>20191005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>87</td>\n",
       "      <td>20190910</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>272</td>\n",
       "      <td>20191007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>68</td>\n",
       "      <td>20190909</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>187</td>\n",
       "      <td>250</td>\n",
       "      <td>20191001</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   记录数  num  num_1      riqi\n",
       "0    1   24    132  20191005\n",
       "1    1    1     87  20190910\n",
       "2    1   24    272  20191007\n",
       "3    1    4     68  20190909\n",
       "4    1  187    250  20191001"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用select_dtypes()，选取整数列\n",
    "dt.select_dtypes(include=['int64']).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:50:57.621693Z",
     "start_time": "2019-10-24T01:50:57.607729Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>记录数</th>\n",
       "      <th>num</th>\n",
       "      <th>num_1</th>\n",
       "      <th>riqi</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>132</td>\n",
       "      <td>20191005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>87</td>\n",
       "      <td>20190910</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>272</td>\n",
       "      <td>20191007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>68</td>\n",
       "      <td>20190909</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>187</td>\n",
       "      <td>250</td>\n",
       "      <td>20191001</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   记录数  num  num_1      riqi\n",
       "0    1   24    132  20191005\n",
       "1    1    1     87  20190910\n",
       "2    1   24    272  20191007\n",
       "3    1    4     68  20190909\n",
       "4    1  187    250  20191001"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取所有的数值列\n",
    "dt.select_dtypes(include=['number']).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:52:57.747480Z",
     "start_time": "2019-10-24T01:52:57.735471Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>num</th>\n",
       "      <th>num_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>24</td>\n",
       "      <td>132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>24</td>\n",
       "      <td>272</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>187</td>\n",
       "      <td>250</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   num  num_1\n",
       "0   24    132\n",
       "1    1     87\n",
       "2   24    272\n",
       "3    4     68\n",
       "4  187    250"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过filter（）函数过滤选取多列\n",
    "dt.filter(like='num').head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:54:25.071910Z",
     "start_time": "2019-10-24T01:54:25.061934Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>num_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>272</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>250</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   num_1\n",
       "0    132\n",
       "1     87\n",
       "2    272\n",
       "3     68\n",
       "4    250"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过正则表达式选取多列\n",
    "dt.filter(regex='\\d').head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:55:21.357382Z",
     "start_time": "2019-10-24T01:55:21.342426Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>num</th>\n",
       "      <th>city</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>24</td>\n",
       "      <td>青岛市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>青岛市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>24</td>\n",
       "      <td>合肥市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>青岛市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>187</td>\n",
       "      <td>合肥市</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   num city\n",
       "0   24  青岛市\n",
       "1    1  青岛市\n",
       "2   24  合肥市\n",
       "3    4  青岛市\n",
       "4  187  合肥市"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# filter()函数，传递列表到参数items，选取多列\n",
    "dt.filter(items=['num','city']).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 对列名进行排序\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:56:01.060205Z",
     "start_time": "2019-10-24T01:56:01.039263Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>记录数</th>\n",
       "      <th>city</th>\n",
       "      <th>credit_by</th>\n",
       "      <th>num</th>\n",
       "      <th>num_1</th>\n",
       "      <th>riqi</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>青岛市</td>\n",
       "      <td>HUABEI</td>\n",
       "      <td>24</td>\n",
       "      <td>132</td>\n",
       "      <td>20191005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>青岛市</td>\n",
       "      <td>YUEBAO</td>\n",
       "      <td>1</td>\n",
       "      <td>87</td>\n",
       "      <td>20190910</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>YUANDONGRONGZU</td>\n",
       "      <td>24</td>\n",
       "      <td>272</td>\n",
       "      <td>20191007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>青岛市</td>\n",
       "      <td>TIANCHENGRONGZU</td>\n",
       "      <td>4</td>\n",
       "      <td>68</td>\n",
       "      <td>20190909</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>HUABEI</td>\n",
       "      <td>187</td>\n",
       "      <td>250</td>\n",
       "      <td>20191001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>479</th>\n",
       "      <td>1</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>YUEBAO</td>\n",
       "      <td>2</td>\n",
       "      <td>193</td>\n",
       "      <td>20190902</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>480</th>\n",
       "      <td>1</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>HUABEI</td>\n",
       "      <td>105</td>\n",
       "      <td>193</td>\n",
       "      <td>20190902</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>481</th>\n",
       "      <td>1</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>YUEBAO</td>\n",
       "      <td>11</td>\n",
       "      <td>247</td>\n",
       "      <td>20190925</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>482</th>\n",
       "      <td>1</td>\n",
       "      <td>青岛市</td>\n",
       "      <td>TIANCHENGRONGZU</td>\n",
       "      <td>10</td>\n",
       "      <td>135</td>\n",
       "      <td>20190913</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>483</th>\n",
       "      <td>1</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>DELEKEJI</td>\n",
       "      <td>1</td>\n",
       "      <td>247</td>\n",
       "      <td>20190925</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>484 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     记录数 city        credit_by  num  num_1      riqi\n",
       "0      1  青岛市           HUABEI   24    132  20191005\n",
       "1      1  青岛市           YUEBAO    1     87  20190910\n",
       "2      1  合肥市   YUANDONGRONGZU   24    272  20191007\n",
       "3      1  青岛市  TIANCHENGRONGZU    4     68  20190909\n",
       "4      1  合肥市           HUABEI  187    250  20191001\n",
       "..   ...  ...              ...  ...    ...       ...\n",
       "479    1  合肥市           YUEBAO    2    193  20190902\n",
       "480    1  合肥市           HUABEI  105    193  20190902\n",
       "481    1  合肥市           YUEBAO   11    247  20190925\n",
       "482    1  青岛市  TIANCHENGRONGZU   10    135  20190913\n",
       "483    1  合肥市         DELEKEJI    1    247  20190925\n",
       "\n",
       "[484 rows x 6 columns]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取数据\n",
    "dt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:56:44.133023Z",
     "start_time": "2019-10-24T01:56:44.126035Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['记录数', 'city', 'credit_by', 'num', 'num_1', 'riqi'], dtype='object')"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:58:08.068327Z",
     "start_time": "2019-10-24T01:58:08.063341Z"
    }
   },
   "outputs": [],
   "source": [
    "new_col = ['riqi', '记录数', 'city', 'credit_by', 'num', 'num_1']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:58:24.799586Z",
     "start_time": "2019-10-24T01:58:24.792605Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "set(dt.columns) == set(new_col)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:58:37.581409Z",
     "start_time": "2019-10-24T01:58:37.559496Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>riqi</th>\n",
       "      <th>记录数</th>\n",
       "      <th>city</th>\n",
       "      <th>credit_by</th>\n",
       "      <th>num</th>\n",
       "      <th>num_1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20191005</td>\n",
       "      <td>1</td>\n",
       "      <td>青岛市</td>\n",
       "      <td>HUABEI</td>\n",
       "      <td>24</td>\n",
       "      <td>132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20190910</td>\n",
       "      <td>1</td>\n",
       "      <td>青岛市</td>\n",
       "      <td>YUEBAO</td>\n",
       "      <td>1</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20191007</td>\n",
       "      <td>1</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>YUANDONGRONGZU</td>\n",
       "      <td>24</td>\n",
       "      <td>272</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20190909</td>\n",
       "      <td>1</td>\n",
       "      <td>青岛市</td>\n",
       "      <td>TIANCHENGRONGZU</td>\n",
       "      <td>4</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20191001</td>\n",
       "      <td>1</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>HUABEI</td>\n",
       "      <td>187</td>\n",
       "      <td>250</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>479</th>\n",
       "      <td>20190902</td>\n",
       "      <td>1</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>YUEBAO</td>\n",
       "      <td>2</td>\n",
       "      <td>193</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>480</th>\n",
       "      <td>20190902</td>\n",
       "      <td>1</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>HUABEI</td>\n",
       "      <td>105</td>\n",
       "      <td>193</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>481</th>\n",
       "      <td>20190925</td>\n",
       "      <td>1</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>YUEBAO</td>\n",
       "      <td>11</td>\n",
       "      <td>247</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>482</th>\n",
       "      <td>20190913</td>\n",
       "      <td>1</td>\n",
       "      <td>青岛市</td>\n",
       "      <td>TIANCHENGRONGZU</td>\n",
       "      <td>10</td>\n",
       "      <td>135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>483</th>\n",
       "      <td>20190925</td>\n",
       "      <td>1</td>\n",
       "      <td>合肥市</td>\n",
       "      <td>DELEKEJI</td>\n",
       "      <td>1</td>\n",
       "      <td>247</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>484 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         riqi  记录数 city        credit_by  num  num_1\n",
       "0    20191005    1  青岛市           HUABEI   24    132\n",
       "1    20190910    1  青岛市           YUEBAO    1     87\n",
       "2    20191007    1  合肥市   YUANDONGRONGZU   24    272\n",
       "3    20190909    1  青岛市  TIANCHENGRONGZU    4     68\n",
       "4    20191001    1  合肥市           HUABEI  187    250\n",
       "..        ...  ...  ...              ...  ...    ...\n",
       "479  20190902    1  合肥市           YUEBAO    2    193\n",
       "480  20190902    1  合肥市           HUABEI  105    193\n",
       "481  20190925    1  合肥市           YUEBAO   11    247\n",
       "482  20190913    1  青岛市  TIANCHENGRONGZU   10    135\n",
       "483  20190925    1  合肥市         DELEKEJI    1    247\n",
       "\n",
       "[484 rows x 6 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt2 = dt[new_col]\n",
    "dt2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 在整个DataFrame上操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-24T01:59:49.794267Z",
     "start_time": "2019-10-24T01:59:49.782303Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(484, 6)"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 打印行和列数\n",
    "dt.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T02:23:19.834060Z",
     "start_time": "2019-10-25T02:23:19.820097Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2904"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 打印数据的个数\n",
    "dt.size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T02:23:51.287948Z",
     "start_time": "2019-10-25T02:23:51.280961Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 该数据的维度\n",
    "dt.ndim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T02:24:32.878720Z",
     "start_time": "2019-10-25T02:24:32.873733Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "484"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 该数据的长度\n",
    "len(dt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T02:25:10.965863Z",
     "start_time": "2019-10-25T02:25:10.951900Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "记录数          484\n",
       "city         484\n",
       "credit_by    484\n",
       "num          484\n",
       "num_1        484\n",
       "riqi         484\n",
       "dtype: int64"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 各个列的值的个数\n",
    "dt.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T02:25:46.115863Z",
     "start_time": "2019-10-25T02:25:46.104891Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "记录数                 1\n",
       "city              合肥市\n",
       "credit_by    DELEKEJI\n",
       "num                 1\n",
       "num_1              13\n",
       "riqi         20190901\n",
       "dtype: object"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 各列的最小值\n",
    "dt.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T02:28:43.147334Z",
     "start_time": "2019-10-25T02:28:43.080485Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>记录数</th>\n",
       "      <th>num</th>\n",
       "      <th>num_1</th>\n",
       "      <th>riqi</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>484.0</td>\n",
       "      <td>484.000000</td>\n",
       "      <td>484.000000</td>\n",
       "      <td>4.840000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>1.0</td>\n",
       "      <td>32.520661</td>\n",
       "      <td>187.134298</td>\n",
       "      <td>2.019094e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.0</td>\n",
       "      <td>40.892648</td>\n",
       "      <td>69.678681</td>\n",
       "      <td>4.288286e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>13.000000</td>\n",
       "      <td>2.019090e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>1.0</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>135.000000</td>\n",
       "      <td>2.019091e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>1.0</td>\n",
       "      <td>17.000000</td>\n",
       "      <td>204.000000</td>\n",
       "      <td>2.019092e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.0</td>\n",
       "      <td>43.250000</td>\n",
       "      <td>241.000000</td>\n",
       "      <td>2.019100e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.0</td>\n",
       "      <td>203.000000</td>\n",
       "      <td>335.000000</td>\n",
       "      <td>2.019101e+07</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         记录数         num       num_1          riqi\n",
       "count  484.0  484.000000  484.000000  4.840000e+02\n",
       "mean     1.0   32.520661  187.134298  2.019094e+07\n",
       "std      0.0   40.892648   69.678681  4.288286e+01\n",
       "min      1.0    1.000000   13.000000  2.019090e+07\n",
       "25%      1.0    4.000000  135.000000  2.019091e+07\n",
       "50%      1.0   17.000000  204.000000  2.019092e+07\n",
       "75%      1.0   43.250000  241.000000  2.019100e+07\n",
       "max      1.0  203.000000  335.000000  2.019101e+07"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 打印描述信息\n",
    "dt.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T02:30:31.868550Z",
     "start_time": "2019-10-25T02:30:31.827657Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>记录数</th>\n",
       "      <th>num</th>\n",
       "      <th>num_1</th>\n",
       "      <th>riqi</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>484.0</td>\n",
       "      <td>484.000000</td>\n",
       "      <td>484.000000</td>\n",
       "      <td>4.840000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>1.0</td>\n",
       "      <td>32.520661</td>\n",
       "      <td>187.134298</td>\n",
       "      <td>2.019094e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.0</td>\n",
       "      <td>40.892648</td>\n",
       "      <td>69.678681</td>\n",
       "      <td>4.288286e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>13.000000</td>\n",
       "      <td>2.019090e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1%</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>28.000000</td>\n",
       "      <td>2.019090e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30%</th>\n",
       "      <td>1.0</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>147.900000</td>\n",
       "      <td>2.019091e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>1.0</td>\n",
       "      <td>17.000000</td>\n",
       "      <td>204.000000</td>\n",
       "      <td>2.019092e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99%</th>\n",
       "      <td>1.0</td>\n",
       "      <td>174.170000</td>\n",
       "      <td>305.950000</td>\n",
       "      <td>2.019101e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.0</td>\n",
       "      <td>203.000000</td>\n",
       "      <td>335.000000</td>\n",
       "      <td>2.019101e+07</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         记录数         num       num_1          riqi\n",
       "count  484.0  484.000000  484.000000  4.840000e+02\n",
       "mean     1.0   32.520661  187.134298  2.019094e+07\n",
       "std      0.0   40.892648   69.678681  4.288286e+01\n",
       "min      1.0    1.000000   13.000000  2.019090e+07\n",
       "1%       1.0    1.000000   28.000000  2.019090e+07\n",
       "30%      1.0    6.000000  147.900000  2.019091e+07\n",
       "50%      1.0   17.000000  204.000000  2.019092e+07\n",
       "99%      1.0  174.170000  305.950000  2.019101e+07\n",
       "max      1.0  203.000000  335.000000  2.019101e+07"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用percentiles参数指定分位数\n",
    "pd.options.display.max_rows = 10\n",
    "dt.describe(percentiles=[0.01, 0.3, 0.99])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T02:31:37.299569Z",
     "start_time": "2019-10-25T02:31:37.290591Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "记录数          0\n",
       "city         0\n",
       "credit_by    0\n",
       "num          0\n",
       "num_1        0\n",
       "riqi         0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 打印各列空值的个数\n",
    "dt.isnull().sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 更多"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T02:33:03.987734Z",
     "start_time": "2019-10-25T02:33:03.976765Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "记录数                 1\n",
       "city              合肥市\n",
       "credit_by    DELEKEJI\n",
       "num                 1\n",
       "num_1              13\n",
       "riqi         20190901\n",
       "dtype: object"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 设定skipna=False，没有缺失值的数值列才会计算结果\n",
    "dt.min(skipna=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.串联DataFrame方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T02:35:06.464158Z",
     "start_time": "2019-10-25T02:35:06.449198Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>记录数</th>\n",
       "      <th>city</th>\n",
       "      <th>credit_by</th>\n",
       "      <th>num</th>\n",
       "      <th>num_1</th>\n",
       "      <th>riqi</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     记录数   city  credit_by    num  num_1   riqi\n",
       "0  False  False      False  False  False  False\n",
       "1  False  False      False  False  False  False\n",
       "2  False  False      False  False  False  False\n",
       "3  False  False      False  False  False  False\n",
       "4  False  False      False  False  False  False"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用isnull方法将每个值转变为布尔值\n",
    "dt.isnull().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T02:35:59.692808Z",
     "start_time": "2019-10-25T02:35:59.681836Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "记录数          0\n",
       "city         0\n",
       "credit_by    0\n",
       "num          0\n",
       "num_1        0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用sum统计布尔值，返回的是Series\n",
    "dt.isnull().sum().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T02:38:25.498532Z",
     "start_time": "2019-10-25T02:38:25.488561Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对这个Series再使用sum,返回整个DataFrame的缺失值的个数，返回值是个标量\n",
    "dt.isnull().sum().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T06:49:05.462695Z",
     "start_time": "2019-10-25T06:49:05.449731Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 判断DataFrame有没有缺失值，方法是连着使用两个any\n",
    "dt.isnull().any().any()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T06:52:13.584043Z",
     "start_time": "2019-10-25T06:52:13.574073Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "bool    6\n",
       "dtype: int64"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# isnull返回同样大小的DataFrame，但所有的值变为布尔值\n",
    "dt.isnull().get_dtype_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 更多\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T06:56:00.975822Z",
     "start_time": "2019-10-25T06:56:00.967804Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "203"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据集的对象数据包含缺失值。默认条件下，聚合方法min、max、sum，\n",
    "# 返回任何值\n",
    "dt['num'].max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T06:57:25.872744Z",
     "start_time": "2019-10-25T06:57:25.857784Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "记录数             1\n",
       "num           203\n",
       "num_1         335\n",
       "riqi     20191014\n",
       "dtype: int64"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 要让pandas强行返回每列的值，必须填入缺失值。\n",
    "dt.select_dtypes(['int64']).fillna(0).max()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5.在DataFrame上使用运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T02:31:22.510875Z",
     "start_time": "2019-10-28T02:31:21.363930Z"
    }
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can only concatenate str (not \"int\") to str",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\ops.py\u001b[0m in \u001b[0;36mna_op\u001b[1;34m(x, y)\u001b[0m\n\u001b[0;32m   1504\u001b[0m         \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1505\u001b[1;33m             \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mexpressions\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mevaluate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstr_rep\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0meval_kwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1506\u001b[0m         \u001b[1;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\computation\\expressions.py\u001b[0m in \u001b[0;36mevaluate\u001b[1;34m(op, op_str, a, b, use_numexpr, **eval_kwargs)\u001b[0m\n\u001b[0;32m    207\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0muse_numexpr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 208\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0m_evaluate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop_str\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0meval_kwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    209\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0m_evaluate_standard\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop_str\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\computation\\expressions.py\u001b[0m in \u001b[0;36m_evaluate_numexpr\u001b[1;34m(op, op_str, a, b, truediv, reversed, **eval_kwargs)\u001b[0m\n\u001b[0;32m    122\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mresult\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 123\u001b[1;33m         \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_evaluate_standard\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop_str\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    124\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\computation\\expressions.py\u001b[0m in \u001b[0;36m_evaluate_standard\u001b[1;34m(op, op_str, a, b, **eval_kwargs)\u001b[0m\n\u001b[0;32m     67\u001b[0m     \u001b[1;32mwith\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merrstate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mall\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'ignore'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 68\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     69\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\ops.py\u001b[0m in \u001b[0;36msafe_na_op\u001b[1;34m(lvalues, rvalues)\u001b[0m\n\u001b[0;32m   1528\u001b[0m             \u001b[1;32mwith\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merrstate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mall\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'ignore'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1529\u001b[1;33m                 \u001b[1;32mreturn\u001b[0m \u001b[0mna_op\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlvalues\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrvalues\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1530\u001b[0m         \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\ops.py\u001b[0m in \u001b[0;36mna_op\u001b[1;34m(x, y)\u001b[0m\n\u001b[0;32m   1506\u001b[0m         \u001b[1;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1507\u001b[1;33m             \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmasked_arith_op\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1508\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\ops.py\u001b[0m in \u001b[0;36mmasked_arith_op\u001b[1;34m(x, y, op)\u001b[0m\n\u001b[0;32m   1025\u001b[0m             \u001b[1;32mwith\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merrstate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mall\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'ignore'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1026\u001b[1;33m                 \u001b[0mresult\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mmask\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mxrav\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mmask\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1027\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-10-4312922046ba>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m# college数据集的值既有数值也有对象，整数5不能与字符串相加\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mcollege\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'college.csv'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mcollege\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\ops.py\u001b[0m in \u001b[0;36mf\u001b[1;34m(self, other, axis, level, fill_value)\u001b[0m\n\u001b[0;32m   2034\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2035\u001b[0m             \u001b[1;32massert\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mother\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2036\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_combine_const\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mother\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2037\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2038\u001b[0m     \u001b[0mf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__name__\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mop_name\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36m_combine_const\u001b[1;34m(self, other, func)\u001b[0m\n\u001b[0;32m   5118\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_combine_const\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mother\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   5119\u001b[0m         \u001b[1;32massert\u001b[0m \u001b[0mlib\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mis_scalar\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mother\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mother\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 5120\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mops\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdispatch_to_series\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mother\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   5121\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   5122\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mcombine\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mother\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfill_value\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moverwrite\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\ops.py\u001b[0m in \u001b[0;36mdispatch_to_series\u001b[1;34m(left, right, func, str_rep, axis)\u001b[0m\n\u001b[0;32m   1155\u001b[0m         \u001b[1;32mraise\u001b[0m \u001b[0mNotImplementedError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mright\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1156\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1157\u001b[1;33m     \u001b[0mnew_data\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mexpressions\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mevaluate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcolumn_op\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstr_rep\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mleft\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mright\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1158\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1159\u001b[0m     \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mleft\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_constructor\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnew_data\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mleft\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\computation\\expressions.py\u001b[0m in \u001b[0;36mevaluate\u001b[1;34m(op, op_str, a, b, use_numexpr, **eval_kwargs)\u001b[0m\n\u001b[0;32m    206\u001b[0m     \u001b[0muse_numexpr\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0muse_numexpr\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0m_bool_arith_check\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mop_str\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    207\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0muse_numexpr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 208\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0m_evaluate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop_str\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0meval_kwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    209\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0m_evaluate_standard\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop_str\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    210\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\computation\\expressions.py\u001b[0m in \u001b[0;36m_evaluate_numexpr\u001b[1;34m(op, op_str, a, b, truediv, reversed, **eval_kwargs)\u001b[0m\n\u001b[0;32m    121\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    122\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mresult\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 123\u001b[1;33m         \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_evaluate_standard\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop_str\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    124\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    125\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\computation\\expressions.py\u001b[0m in \u001b[0;36m_evaluate_standard\u001b[1;34m(op, op_str, a, b, **eval_kwargs)\u001b[0m\n\u001b[0;32m     66\u001b[0m         \u001b[0m_store_test_result\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     67\u001b[0m     \u001b[1;32mwith\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merrstate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mall\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'ignore'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 68\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     69\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     70\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\ops.py\u001b[0m in \u001b[0;36mcolumn_op\u001b[1;34m(a, b)\u001b[0m\n\u001b[0;32m   1126\u001b[0m         \u001b[1;32mdef\u001b[0m \u001b[0mcolumn_op\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1127\u001b[0m             return {i: func(a.iloc[:, i], b)\n\u001b[1;32m-> 1128\u001b[1;33m                     for i in range(len(a.columns))}\n\u001b[0m\u001b[0;32m   1129\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1130\u001b[0m     \u001b[1;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mright\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mABCDataFrame\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\ops.py\u001b[0m in \u001b[0;36m<dictcomp>\u001b[1;34m(.0)\u001b[0m\n\u001b[0;32m   1126\u001b[0m         \u001b[1;32mdef\u001b[0m \u001b[0mcolumn_op\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1127\u001b[0m             return {i: func(a.iloc[:, i], b)\n\u001b[1;32m-> 1128\u001b[1;33m                     for i in range(len(a.columns))}\n\u001b[0m\u001b[0;32m   1129\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1130\u001b[0m     \u001b[1;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mright\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mABCDataFrame\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\ops.py\u001b[0m in \u001b[0;36mwrapper\u001b[1;34m(left, right)\u001b[0m\n\u001b[0;32m   1581\u001b[0m             \u001b[0mrvalues\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrvalues\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1582\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1583\u001b[1;33m         \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msafe_na_op\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlvalues\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrvalues\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1584\u001b[0m         return construct_result(left, result,\n\u001b[0;32m   1585\u001b[0m                                 index=left.index, name=res_name, dtype=None)\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\ops.py\u001b[0m in \u001b[0;36msafe_na_op\u001b[1;34m(lvalues, rvalues)\u001b[0m\n\u001b[0;32m   1531\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mis_object_dtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlvalues\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1532\u001b[0m                 return libalgos.arrmap_object(lvalues,\n\u001b[1;32m-> 1533\u001b[1;33m                                               lambda x: op(x, rvalues))\n\u001b[0m\u001b[0;32m   1534\u001b[0m             \u001b[1;32mraise\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1535\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mpandas/_libs/algos.pyx\u001b[0m in \u001b[0;36mpandas._libs.algos.arrmap\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\ops.py\u001b[0m in \u001b[0;36m<lambda>\u001b[1;34m(x)\u001b[0m\n\u001b[0;32m   1531\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mis_object_dtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlvalues\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1532\u001b[0m                 return libalgos.arrmap_object(lvalues,\n\u001b[1;32m-> 1533\u001b[1;33m                                               lambda x: op(x, rvalues))\n\u001b[0m\u001b[0;32m   1534\u001b[0m             \u001b[1;32mraise\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1535\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str"
     ]
    }
   ],
   "source": [
    "# college数据集的值既有数值也有对象，整数5不能与字符串相加\n",
    "college = pd.read_csv('college.csv')\n",
    "college + 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T07:34:52.945787Z",
     "start_time": "2019-10-25T07:34:52.697451Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\pandas\\core\\ops.py:1649: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison\n",
      "  result = method(y)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>...</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SAE Institute of Technology  San Francisco</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Rasmussen College - Overland Park</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>National Personal Training Institute of Cleveland</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bay Area Medical Academy - San Jose Satellite Location</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Excel Learning Center-San Antonio South</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>...</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>7535 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                     CITY  STABBR   HBCU  \\\n",
       "INSTNM                                                                     \n",
       "Alabama A & M University                            False   False  False   \n",
       "University of Alabama at Birmingham                 False   False  False   \n",
       "Amridge University                                  False   False  False   \n",
       "University of Alabama in Huntsville                 False   False  False   \n",
       "Alabama State University                            False   False  False   \n",
       "...                                                   ...     ...    ...   \n",
       "SAE Institute of Technology  San Francisco          False   False  False   \n",
       "Rasmussen College - Overland Park                   False   False  False   \n",
       "National Personal Training Institute of Cleveland   False   False  False   \n",
       "Bay Area Medical Academy - San Jose Satellite L...  False   False  False   \n",
       "Excel Learning Center-San Antonio South             False   False  False   \n",
       "\n",
       "                                                    MENONLY  WOMENONLY  ...  \\\n",
       "INSTNM                                                                  ...   \n",
       "Alabama A & M University                              False      False  ...   \n",
       "University of Alabama at Birmingham                   False      False  ...   \n",
       "Amridge University                                    False      False  ...   \n",
       "University of Alabama in Huntsville                   False      False  ...   \n",
       "Alabama State University                              False      False  ...   \n",
       "...                                                     ...        ...  ...   \n",
       "SAE Institute of Technology  San Francisco            False      False  ...   \n",
       "Rasmussen College - Overland Park                     False      False  ...   \n",
       "National Personal Training Institute of Cleveland     False      False  ...   \n",
       "Bay Area Medical Academy - San Jose Satellite L...    False      False  ...   \n",
       "Excel Learning Center-San Antonio South               False      False  ...   \n",
       "\n",
       "                                                    PCTPELL  PCTFLOAN  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                              False     False   \n",
       "University of Alabama at Birmingham                   False     False   \n",
       "Amridge University                                    False     False   \n",
       "University of Alabama in Huntsville                   False     False   \n",
       "Alabama State University                              False     False   \n",
       "...                                                     ...       ...   \n",
       "SAE Institute of Technology  San Francisco            False     False   \n",
       "Rasmussen College - Overland Park                     False     False   \n",
       "National Personal Training Institute of Cleveland     False     False   \n",
       "Bay Area Medical Academy - San Jose Satellite L...    False     False   \n",
       "Excel Learning Center-San Antonio South               False     False   \n",
       "\n",
       "                                                    UG25ABV  MD_EARN_WNE_P10  \\\n",
       "INSTNM                                                                         \n",
       "Alabama A & M University                              False            False   \n",
       "University of Alabama at Birmingham                   False            False   \n",
       "Amridge University                                    False            False   \n",
       "University of Alabama in Huntsville                   False            False   \n",
       "Alabama State University                              False            False   \n",
       "...                                                     ...              ...   \n",
       "SAE Institute of Technology  San Francisco            False            False   \n",
       "Rasmussen College - Overland Park                     False            False   \n",
       "National Personal Training Institute of Cleveland     False            False   \n",
       "Bay Area Medical Academy - San Jose Satellite L...    False            False   \n",
       "Excel Learning Center-San Antonio South               False            False   \n",
       "\n",
       "                                                    GRAD_DEBT_MDN_SUPP  \n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                                         False  \n",
       "University of Alabama at Birmingham                              False  \n",
       "Amridge University                                               False  \n",
       "University of Alabama in Huntsville                              False  \n",
       "Alabama State University                                         False  \n",
       "...                                                                ...  \n",
       "SAE Institute of Technology  San Francisco                       False  \n",
       "Rasmussen College - Overland Park                                False  \n",
       "National Personal Training Institute of Cleveland                False  \n",
       "Bay Area Medical Academy - San Jose Satellite L...               False  \n",
       "Excel Learning Center-San Antonio South                          False  \n",
       "\n",
       "[7535 rows x 26 columns]"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 行索引名设为INSTM,用UGDS_过滤出本科生的种族比例\n",
    "college = pd.read_csv('college.csv', index_col='INSTNM')\n",
    "college_ugds_ = college.filter(like='UGDS_')\n",
    "college == 'asdf' # 这是jn上的，想要比较college和‘asdf’，没有意义，忽略"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T07:35:38.948761Z",
     "start_time": "2019-10-25T07:35:38.928814Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.0333</td>\n",
       "      <td>0.9353</td>\n",
       "      <td>0.0055</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0024</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0059</td>\n",
       "      <td>0.0138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.5922</td>\n",
       "      <td>0.2600</td>\n",
       "      <td>0.0283</td>\n",
       "      <td>0.0518</td>\n",
       "      <td>0.0022</td>\n",
       "      <td>0.0007</td>\n",
       "      <td>0.0368</td>\n",
       "      <td>0.0179</td>\n",
       "      <td>0.0100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.2990</td>\n",
       "      <td>0.4192</td>\n",
       "      <td>0.0069</td>\n",
       "      <td>0.0034</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.2715</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.6988</td>\n",
       "      <td>0.1255</td>\n",
       "      <td>0.0382</td>\n",
       "      <td>0.0376</td>\n",
       "      <td>0.0143</td>\n",
       "      <td>0.0002</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.0158</td>\n",
       "      <td>0.9208</td>\n",
       "      <td>0.0121</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0010</td>\n",
       "      <td>0.0006</td>\n",
       "      <td>0.0098</td>\n",
       "      <td>0.0243</td>\n",
       "      <td>0.0137</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                 0.0333      0.9353     0.0055   \n",
       "University of Alabama at Birmingham      0.5922      0.2600     0.0283   \n",
       "Amridge University                       0.2990      0.4192     0.0069   \n",
       "University of Alabama in Huntsville      0.6988      0.1255     0.0382   \n",
       "Alabama State University                 0.0158      0.9208     0.0121   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                 0.0019     0.0024     0.0019   \n",
       "University of Alabama at Birmingham      0.0518     0.0022     0.0007   \n",
       "Amridge University                       0.0034     0.0000     0.0000   \n",
       "University of Alabama in Huntsville      0.0376     0.0143     0.0002   \n",
       "Alabama State University                 0.0019     0.0010     0.0006   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                0.0000    0.0059     0.0138  \n",
       "University of Alabama at Birmingham     0.0368    0.0179     0.0100  \n",
       "Amridge University                      0.0000    0.0000     0.2715  \n",
       "University of Alabama in Huntsville     0.0172    0.0332     0.0350  \n",
       "Alabama State University                0.0098    0.0243     0.0137  "
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看前5行\n",
    "college_ugds_.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T07:36:55.275641Z",
     "start_time": "2019-10-25T07:36:55.250706Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.03831</td>\n",
       "      <td>0.94031</td>\n",
       "      <td>0.01051</td>\n",
       "      <td>0.00691</td>\n",
       "      <td>0.00741</td>\n",
       "      <td>0.00691</td>\n",
       "      <td>0.00501</td>\n",
       "      <td>0.01091</td>\n",
       "      <td>0.01881</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.59721</td>\n",
       "      <td>0.26501</td>\n",
       "      <td>0.03331</td>\n",
       "      <td>0.05681</td>\n",
       "      <td>0.00721</td>\n",
       "      <td>0.00571</td>\n",
       "      <td>0.04181</td>\n",
       "      <td>0.02291</td>\n",
       "      <td>0.01501</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.30401</td>\n",
       "      <td>0.42421</td>\n",
       "      <td>0.01191</td>\n",
       "      <td>0.00841</td>\n",
       "      <td>0.00501</td>\n",
       "      <td>0.00501</td>\n",
       "      <td>0.00501</td>\n",
       "      <td>0.00501</td>\n",
       "      <td>0.27651</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.70381</td>\n",
       "      <td>0.13051</td>\n",
       "      <td>0.04321</td>\n",
       "      <td>0.04261</td>\n",
       "      <td>0.01931</td>\n",
       "      <td>0.00521</td>\n",
       "      <td>0.02221</td>\n",
       "      <td>0.03821</td>\n",
       "      <td>0.04001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.02081</td>\n",
       "      <td>0.92581</td>\n",
       "      <td>0.01711</td>\n",
       "      <td>0.00691</td>\n",
       "      <td>0.00601</td>\n",
       "      <td>0.00561</td>\n",
       "      <td>0.01481</td>\n",
       "      <td>0.02931</td>\n",
       "      <td>0.01871</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                0.03831     0.94031    0.01051   \n",
       "University of Alabama at Birmingham     0.59721     0.26501    0.03331   \n",
       "Amridge University                      0.30401     0.42421    0.01191   \n",
       "University of Alabama in Huntsville     0.70381     0.13051    0.04321   \n",
       "Alabama State University                0.02081     0.92581    0.01711   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                0.00691    0.00741    0.00691   \n",
       "University of Alabama at Birmingham     0.05681    0.00721    0.00571   \n",
       "Amridge University                      0.00841    0.00501    0.00501   \n",
       "University of Alabama in Huntsville     0.04261    0.01931    0.00521   \n",
       "Alabama State University                0.00691    0.00601    0.00561   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University               0.00501   0.01091    0.01881  \n",
       "University of Alabama at Birmingham    0.04181   0.02291    0.01501  \n",
       "Amridge University                     0.00501   0.00501    0.27651  \n",
       "University of Alabama in Huntsville    0.02221   0.03821    0.04001  \n",
       "Alabama State University               0.01481   0.02931    0.01871  "
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 现在是均质数据了，可以进行数值运算\n",
    "college_ugds_.head() + 0.00501"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T07:37:57.749566Z",
     "start_time": "2019-10-25T07:37:57.720645Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>3.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>59.0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>30.0</td>\n",
       "      <td>42.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>27.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>70.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>2.0</td>\n",
       "      <td>92.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                    3.0        94.0        1.0   \n",
       "University of Alabama at Birmingham        59.0        26.0        3.0   \n",
       "Amridge University                         30.0        42.0        1.0   \n",
       "University of Alabama in Huntsville        70.0        13.0        4.0   \n",
       "Alabama State University                    2.0        92.0        1.0   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                    0.0        0.0        0.0   \n",
       "University of Alabama at Birmingham         5.0        0.0        0.0   \n",
       "Amridge University                          0.0        0.0        0.0   \n",
       "University of Alabama in Huntsville         4.0        1.0        0.0   \n",
       "Alabama State University                    0.0        0.0        0.0   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                   0.0       1.0        1.0  \n",
       "University of Alabama at Birmingham        4.0       2.0        1.0  \n",
       "Amridge University                         0.0       0.0       27.0  \n",
       "University of Alabama in Huntsville        2.0       3.0        4.0  \n",
       "Alabama State University                   1.0       2.0        1.0  "
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用底除计算百分比分数\n",
    "(college_ugds_.head() + .00501) // .01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T07:39:14.465404Z",
     "start_time": "2019-10-25T07:39:14.431498Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.03</td>\n",
       "      <td>0.94</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.59</td>\n",
       "      <td>0.26</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.30</td>\n",
       "      <td>0.42</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.70</td>\n",
       "      <td>0.13</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.02</td>\n",
       "      <td>0.92</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                   0.03        0.94       0.01   \n",
       "University of Alabama at Birmingham        0.59        0.26       0.03   \n",
       "Amridge University                         0.30        0.42       0.01   \n",
       "University of Alabama in Huntsville        0.70        0.13       0.04   \n",
       "Alabama State University                   0.02        0.92       0.01   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                   0.00       0.00        0.0   \n",
       "University of Alabama at Birmingham        0.05       0.00        0.0   \n",
       "Amridge University                         0.00       0.00        0.0   \n",
       "University of Alabama in Huntsville        0.04       0.01        0.0   \n",
       "Alabama State University                   0.00       0.00        0.0   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                  0.00      0.01       0.01  \n",
       "University of Alabama at Birmingham       0.04      0.02       0.01  \n",
       "Amridge University                        0.00      0.00       0.27  \n",
       "University of Alabama in Huntsville       0.02      0.03       0.04  \n",
       "Alabama State University                  0.01      0.02       0.01  "
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 再除以100\n",
    "college_ugds_op_round = (college_ugds_.head() + .00501) // .01 /100\n",
    "college_ugds_op_round.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T07:40:35.955476Z",
     "start_time": "2019-10-25T07:40:35.929544Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.03</td>\n",
       "      <td>0.94</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.59</td>\n",
       "      <td>0.26</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.30</td>\n",
       "      <td>0.42</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.70</td>\n",
       "      <td>0.13</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.02</td>\n",
       "      <td>0.92</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                   0.03        0.94       0.01   \n",
       "University of Alabama at Birmingham        0.59        0.26       0.03   \n",
       "Amridge University                         0.30        0.42       0.01   \n",
       "University of Alabama in Huntsville        0.70        0.13       0.04   \n",
       "Alabama State University                   0.02        0.92       0.01   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                   0.00       0.00        0.0   \n",
       "University of Alabama at Birmingham        0.05       0.00        0.0   \n",
       "Amridge University                         0.00       0.00        0.0   \n",
       "University of Alabama in Huntsville        0.04       0.01        0.0   \n",
       "Alabama State University                   0.00       0.00        0.0   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                  0.00      0.01       0.01  \n",
       "University of Alabama at Birmingham       0.04      0.02       0.01  \n",
       "Amridge University                        0.00      0.00       0.27  \n",
       "University of Alabama in Huntsville       0.02      0.03       0.04  \n",
       "Alabama State University                  0.01      0.02       0.01  "
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 保留两位小数\n",
    "college_ugds_round = (college_ugds_.head() + .00001).round(2)\n",
    "college_ugds_round"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T07:41:24.415877Z",
     "start_time": "2019-10-25T07:41:24.408895Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.049999999999999996"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    ".045 + .005"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T07:42:09.895255Z",
     "start_time": "2019-10-25T07:42:09.890266Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_op_round.equals(college_ugds_round)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T07:42:57.862972Z",
     "start_time": "2019-10-25T07:42:57.855990Z"
    }
   },
   "source": [
    "##### 更多\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T07:49:54.466090Z",
     "start_time": "2019-10-25T07:49:54.441157Z"
    }
   },
   "outputs": [],
   "source": [
    "# DataFrame的通用函数也可以实现上述方法\n",
    "college_ugds_op_round_methods = college_ugds_.add(.00501).floordiv(0.01).div(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T07:50:07.093320Z",
     "start_time": "2019-10-25T07:50:07.072376Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.03</td>\n",
       "      <td>0.94</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.59</td>\n",
       "      <td>0.26</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.30</td>\n",
       "      <td>0.42</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.70</td>\n",
       "      <td>0.13</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.02</td>\n",
       "      <td>0.92</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SAE Institute of Technology  San Francisco</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Rasmussen College - Overland Park</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>National Personal Training Institute of Cleveland</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bay Area Medical Academy - San Jose Satellite Location</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Excel Learning Center-San Antonio South</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>7535 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                    UGDS_WHITE  UGDS_BLACK  \\\n",
       "INSTNM                                                                       \n",
       "Alabama A & M University                                  0.03        0.94   \n",
       "University of Alabama at Birmingham                       0.59        0.26   \n",
       "Amridge University                                        0.30        0.42   \n",
       "University of Alabama in Huntsville                       0.70        0.13   \n",
       "Alabama State University                                  0.02        0.92   \n",
       "...                                                        ...         ...   \n",
       "SAE Institute of Technology  San Francisco                 NaN         NaN   \n",
       "Rasmussen College - Overland Park                          NaN         NaN   \n",
       "National Personal Training Institute of Cleveland          NaN         NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...         NaN         NaN   \n",
       "Excel Learning Center-San Antonio South                    NaN         NaN   \n",
       "\n",
       "                                                    UGDS_HISP  UGDS_ASIAN  \\\n",
       "INSTNM                                                                      \n",
       "Alabama A & M University                                 0.01        0.00   \n",
       "University of Alabama at Birmingham                      0.03        0.05   \n",
       "Amridge University                                       0.01        0.00   \n",
       "University of Alabama in Huntsville                      0.04        0.04   \n",
       "Alabama State University                                 0.01        0.00   \n",
       "...                                                       ...         ...   \n",
       "SAE Institute of Technology  San Francisco                NaN         NaN   \n",
       "Rasmussen College - Overland Park                         NaN         NaN   \n",
       "National Personal Training Institute of Cleveland         NaN         NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN         NaN   \n",
       "Excel Learning Center-San Antonio South                   NaN         NaN   \n",
       "\n",
       "                                                    UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                     \n",
       "Alabama A & M University                                 0.00        0.0   \n",
       "University of Alabama at Birmingham                      0.00        0.0   \n",
       "Amridge University                                       0.00        0.0   \n",
       "University of Alabama in Huntsville                      0.01        0.0   \n",
       "Alabama State University                                 0.00        0.0   \n",
       "...                                                       ...        ...   \n",
       "SAE Institute of Technology  San Francisco                NaN        NaN   \n",
       "Rasmussen College - Overland Park                         NaN        NaN   \n",
       "National Personal Training Institute of Cleveland         NaN        NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN        NaN   \n",
       "Excel Learning Center-San Antonio South                   NaN        NaN   \n",
       "\n",
       "                                                    UGDS_2MOR  UGDS_NRA  \\\n",
       "INSTNM                                                                    \n",
       "Alabama A & M University                                 0.00      0.01   \n",
       "University of Alabama at Birmingham                      0.04      0.02   \n",
       "Amridge University                                       0.00      0.00   \n",
       "University of Alabama in Huntsville                      0.02      0.03   \n",
       "Alabama State University                                 0.01      0.02   \n",
       "...                                                       ...       ...   \n",
       "SAE Institute of Technology  San Francisco                NaN       NaN   \n",
       "Rasmussen College - Overland Park                         NaN       NaN   \n",
       "National Personal Training Institute of Cleveland         NaN       NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN       NaN   \n",
       "Excel Learning Center-San Antonio South                   NaN       NaN   \n",
       "\n",
       "                                                    UGDS_UNKN  \n",
       "INSTNM                                                         \n",
       "Alabama A & M University                                 0.01  \n",
       "University of Alabama at Birmingham                      0.01  \n",
       "Amridge University                                       0.27  \n",
       "University of Alabama in Huntsville                      0.04  \n",
       "Alabama State University                                 0.01  \n",
       "...                                                       ...  \n",
       "SAE Institute of Technology  San Francisco                NaN  \n",
       "Rasmussen College - Overland Park                         NaN  \n",
       "National Personal Training Institute of Cleveland         NaN  \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN  \n",
       "Excel Learning Center-San Antonio South                   NaN  \n",
       "\n",
       "[7535 rows x 9 columns]"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_op_round_methods"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6.比较缺失值\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T07:52:07.814507Z",
     "start_time": "2019-10-25T07:52:07.807526Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Pandas使用Numpy NaN(np.nan) 对象表示缺失值。这是一个不等于自身的特殊对象：\n",
    "np.nan == np.nan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-25T07:52:38.623084Z",
     "start_time": "2019-10-25T07:52:38.616102Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Python 的None对象是等于自身的\n",
    "None == None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T01:36:08.717026Z",
     "start_time": "2019-10-28T01:36:08.711041Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 所有和np.nan的比较都返回False，除了不等于\n",
    "5 > np.nan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T01:36:29.837542Z",
     "start_time": "2019-10-28T01:36:29.830562Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.nan > 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T01:36:58.573696Z",
     "start_time": "2019-10-28T01:36:58.566717Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5 == np.nan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T01:37:17.254740Z",
     "start_time": "2019-10-28T01:37:17.247753Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5 != np.nan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T05:37:26.203156Z",
     "start_time": "2019-10-28T05:37:26.095443Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   UGDS_WHITE  UGDS_BLACK  UGDS_HISP  UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "0       False       False      False        True      False       True   \n",
       "1       False       False      False       False      False      False   \n",
       "2       False       False      False       False      False      False   \n",
       "3       False       False      False       False      False      False   \n",
       "4       False       False      False        True      False      False   \n",
       "\n",
       "   UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "0      False     False      False  \n",
       "1      False     False      False  \n",
       "2      False     False      False  \n",
       "3      False     False      False  \n",
       "4      False     False      False  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# college_ugds_所有值和.0019比较，返回布尔值DataFrame\n",
    "college_ugds_ = college.filter(like='UGDS_')\n",
    "college_ugds_.head() == .0019"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T05:39:13.158129Z",
     "start_time": "2019-10-28T05:39:13.127220Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7530</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7531</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7532</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7533</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7534</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>7535 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      UGDS_WHITE  UGDS_BLACK  UGDS_HISP  UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "0           True        True       True        True       True       True   \n",
       "1           True        True       True        True       True       True   \n",
       "2           True        True       True        True       True       True   \n",
       "3           True        True       True        True       True       True   \n",
       "4           True        True       True        True       True       True   \n",
       "...          ...         ...        ...         ...        ...        ...   \n",
       "7530       False       False      False       False      False      False   \n",
       "7531       False       False      False       False      False      False   \n",
       "7532       False       False      False       False      False      False   \n",
       "7533       False       False      False       False      False      False   \n",
       "7534       False       False      False       False      False      False   \n",
       "\n",
       "      UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "0          True      True       True  \n",
       "1          True      True       True  \n",
       "2          True      True       True  \n",
       "3          True      True       True  \n",
       "4          True      True       True  \n",
       "...         ...       ...        ...  \n",
       "7530      False     False      False  \n",
       "7531      False     False      False  \n",
       "7532      False     False      False  \n",
       "7533      False     False      False  \n",
       "7534      False     False      False  \n",
       "\n",
       "[7535 rows x 9 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用DataFrame和DataFrame进行比较\n",
    "college_self_compare = college_ugds_ == college_ugds_\n",
    "college_self_compare"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T05:40:36.520480Z",
     "start_time": "2019-10-28T05:40:36.510510Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    False\n",
       "UGDS_BLACK    False\n",
       "UGDS_HISP     False\n",
       "UGDS_ASIAN    False\n",
       "UGDS_AIAN     False\n",
       "UGDS_NHPI     False\n",
       "UGDS_2MOR     False\n",
       "UGDS_NRA      False\n",
       "UGDS_UNKN     False\n",
       "dtype: bool"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# all() 检查是否所有的值都是True；这是因为缺失值不互相等于\n",
    "college_self_compare.all()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T05:43:05.494726Z",
     "start_time": "2019-10-28T05:43:05.478767Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    0\n",
       "UGDS_BLACK    0\n",
       "UGDS_HISP     0\n",
       "UGDS_ASIAN    0\n",
       "UGDS_AIAN     0\n",
       "UGDS_NHPI     0\n",
       "UGDS_2MOR     0\n",
       "UGDS_NRA      0\n",
       "UGDS_UNKN     0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 可以用==号判断，然后求和\n",
    "(college_ugds_ == np.nan).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T05:46:22.289443Z",
     "start_time": "2019-10-28T05:46:22.278467Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    661\n",
       "UGDS_BLACK    661\n",
       "UGDS_HISP     661\n",
       "UGDS_ASIAN    661\n",
       "UGDS_AIAN     661\n",
       "UGDS_NHPI     661\n",
       "UGDS_2MOR     661\n",
       "UGDS_NRA      661\n",
       "UGDS_UNKN     661\n",
       "dtype: int64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 统计缺失值最主要的方法是使用isnull方法：\n",
    "college_ugds_.isnull().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T05:54:05.622424Z",
     "start_time": "2019-10-28T05:54:05.607462Z"
    }
   },
   "outputs": [],
   "source": [
    "# 比较两个DataFrame的最直接的方法是使用equals（）方法\n",
    "from pandas.testing import assert_frame_equal\n",
    "assert_frame_equal(college_ugds_, college_ugds_)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 更多"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T05:55:10.103980Z",
     "start_time": "2019-10-28T05:55:10.078048Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   UGDS_WHITE  UGDS_BLACK  UGDS_HISP  UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "0       False       False      False        True      False       True   \n",
       "1       False       False      False       False      False      False   \n",
       "2       False       False      False       False      False      False   \n",
       "3       False       False      False       False      False      False   \n",
       "4       False       False      False        True      False      False   \n",
       "\n",
       "   UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "0      False     False      False  \n",
       "1      False     False      False  \n",
       "2      False     False      False  \n",
       "3      False     False      False  \n",
       "4      False     False      False  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# eq（）方法类似于==，和前面的equals有所不同\n",
    "college_ugds_.eq(.0019).head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7.矩阵转置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T05:58:01.662995Z",
     "start_time": "2019-10-28T05:58:01.566255Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.0333</td>\n",
       "      <td>0.9353</td>\n",
       "      <td>0.0055</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0024</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0059</td>\n",
       "      <td>0.0138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.5922</td>\n",
       "      <td>0.2600</td>\n",
       "      <td>0.0283</td>\n",
       "      <td>0.0518</td>\n",
       "      <td>0.0022</td>\n",
       "      <td>0.0007</td>\n",
       "      <td>0.0368</td>\n",
       "      <td>0.0179</td>\n",
       "      <td>0.0100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.2990</td>\n",
       "      <td>0.4192</td>\n",
       "      <td>0.0069</td>\n",
       "      <td>0.0034</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.2715</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.6988</td>\n",
       "      <td>0.1255</td>\n",
       "      <td>0.0382</td>\n",
       "      <td>0.0376</td>\n",
       "      <td>0.0143</td>\n",
       "      <td>0.0002</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.0158</td>\n",
       "      <td>0.9208</td>\n",
       "      <td>0.0121</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0010</td>\n",
       "      <td>0.0006</td>\n",
       "      <td>0.0098</td>\n",
       "      <td>0.0243</td>\n",
       "      <td>0.0137</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                 0.0333      0.9353     0.0055   \n",
       "University of Alabama at Birmingham      0.5922      0.2600     0.0283   \n",
       "Amridge University                       0.2990      0.4192     0.0069   \n",
       "University of Alabama in Huntsville      0.6988      0.1255     0.0382   \n",
       "Alabama State University                 0.0158      0.9208     0.0121   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                 0.0019     0.0024     0.0019   \n",
       "University of Alabama at Birmingham      0.0518     0.0022     0.0007   \n",
       "Amridge University                       0.0034     0.0000     0.0000   \n",
       "University of Alabama in Huntsville      0.0376     0.0143     0.0002   \n",
       "Alabama State University                 0.0019     0.0010     0.0006   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                0.0000    0.0059     0.0138  \n",
       "University of Alabama at Birmingham     0.0368    0.0179     0.0100  \n",
       "Amridge University                      0.0000    0.0000     0.2715  \n",
       "University of Alabama in Huntsville     0.0172    0.0332     0.0350  \n",
       "Alabama State University                0.0098    0.0243     0.0137  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college = pd.read_csv('college.csv', index_col='INSTNM')\n",
    "college_ugds_ = college.filter(like='UGDS_')\n",
    "college_ugds_.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T05:59:57.171092Z",
     "start_time": "2019-10-28T05:59:57.158124Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    6874\n",
       "UGDS_BLACK    6874\n",
       "UGDS_HISP     6874\n",
       "UGDS_ASIAN    6874\n",
       "UGDS_AIAN     6874\n",
       "UGDS_NHPI     6874\n",
       "UGDS_2MOR     6874\n",
       "UGDS_NRA      6874\n",
       "UGDS_UNKN     6874\n",
       "dtype: int64"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#count()返回非缺失值的个数\n",
    "college_ugds_.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T06:00:54.112827Z",
     "start_time": "2019-10-28T06:00:54.101840Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    6874\n",
       "UGDS_BLACK    6874\n",
       "UGDS_HISP     6874\n",
       "UGDS_ASIAN    6874\n",
       "UGDS_AIAN     6874\n",
       "UGDS_NHPI     6874\n",
       "UGDS_2MOR     6874\n",
       "UGDS_NRA      6874\n",
       "UGDS_UNKN     6874\n",
       "dtype: int64"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# axis默认设为0\n",
    "college_ugds_.count(axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T06:01:58.033867Z",
     "start_time": "2019-10-28T06:01:58.021898Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    6874\n",
       "UGDS_BLACK    6874\n",
       "UGDS_HISP     6874\n",
       "UGDS_ASIAN    6874\n",
       "UGDS_AIAN     6874\n",
       "UGDS_NHPI     6874\n",
       "UGDS_2MOR     6874\n",
       "UGDS_NRA      6874\n",
       "UGDS_UNKN     6874\n",
       "dtype: int64"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 等价于axis='index'\n",
    "college_ugds_.count(axis='index')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T06:02:44.996276Z",
     "start_time": "2019-10-28T06:02:44.982316Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama A & M University               9\n",
       "University of Alabama at Birmingham    9\n",
       "Amridge University                     9\n",
       "University of Alabama in Huntsville    9\n",
       "Alabama State University               9\n",
       "dtype: int64"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 统计每行的非缺失个数\n",
    "college_ugds_.count(axis='columns').head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T06:04:13.625254Z",
     "start_time": "2019-10-28T06:04:13.614282Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama A & M University               1.0000\n",
       "University of Alabama at Birmingham    0.9999\n",
       "Amridge University                     1.0000\n",
       "University of Alabama in Huntsville    1.0000\n",
       "Alabama State University               1.0000\n",
       "dtype: float64"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 除了统计每行的非缺失值个数，也可以求和加以确认\n",
    "college_ugds_.sum(axis='columns').head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T06:05:13.313630Z",
     "start_time": "2019-10-28T06:05:13.303655Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    0.55570\n",
       "UGDS_BLACK    0.10005\n",
       "UGDS_HISP     0.07140\n",
       "UGDS_ASIAN    0.01290\n",
       "UGDS_AIAN     0.00260\n",
       "UGDS_NHPI     0.00000\n",
       "UGDS_2MOR     0.01750\n",
       "UGDS_NRA      0.00000\n",
       "UGDS_UNKN     0.01430\n",
       "dtype: float64"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用中位数了解每列的分布\n",
    "college_ugds_.median(axis='index')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 更多\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T06:08:15.104223Z",
     "start_time": "2019-10-28T06:08:15.077295Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.0333</td>\n",
       "      <td>0.9686</td>\n",
       "      <td>0.9741</td>\n",
       "      <td>0.9760</td>\n",
       "      <td>0.9784</td>\n",
       "      <td>0.9803</td>\n",
       "      <td>0.9803</td>\n",
       "      <td>0.9862</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.5922</td>\n",
       "      <td>0.8522</td>\n",
       "      <td>0.8805</td>\n",
       "      <td>0.9323</td>\n",
       "      <td>0.9345</td>\n",
       "      <td>0.9352</td>\n",
       "      <td>0.9720</td>\n",
       "      <td>0.9899</td>\n",
       "      <td>0.9999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.2990</td>\n",
       "      <td>0.7182</td>\n",
       "      <td>0.7251</td>\n",
       "      <td>0.7285</td>\n",
       "      <td>0.7285</td>\n",
       "      <td>0.7285</td>\n",
       "      <td>0.7285</td>\n",
       "      <td>0.7285</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.6988</td>\n",
       "      <td>0.8243</td>\n",
       "      <td>0.8625</td>\n",
       "      <td>0.9001</td>\n",
       "      <td>0.9144</td>\n",
       "      <td>0.9146</td>\n",
       "      <td>0.9318</td>\n",
       "      <td>0.9650</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.0158</td>\n",
       "      <td>0.9366</td>\n",
       "      <td>0.9487</td>\n",
       "      <td>0.9506</td>\n",
       "      <td>0.9516</td>\n",
       "      <td>0.9522</td>\n",
       "      <td>0.9620</td>\n",
       "      <td>0.9863</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SAE Institute of Technology  San Francisco</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Rasmussen College - Overland Park</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>National Personal Training Institute of Cleveland</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bay Area Medical Academy - San Jose Satellite Location</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Excel Learning Center-San Antonio South</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>7535 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                    UGDS_WHITE  UGDS_BLACK  \\\n",
       "INSTNM                                                                       \n",
       "Alabama A & M University                                0.0333      0.9686   \n",
       "University of Alabama at Birmingham                     0.5922      0.8522   \n",
       "Amridge University                                      0.2990      0.7182   \n",
       "University of Alabama in Huntsville                     0.6988      0.8243   \n",
       "Alabama State University                                0.0158      0.9366   \n",
       "...                                                        ...         ...   \n",
       "SAE Institute of Technology  San Francisco                 NaN         NaN   \n",
       "Rasmussen College - Overland Park                          NaN         NaN   \n",
       "National Personal Training Institute of Cleveland          NaN         NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...         NaN         NaN   \n",
       "Excel Learning Center-San Antonio South                    NaN         NaN   \n",
       "\n",
       "                                                    UGDS_HISP  UGDS_ASIAN  \\\n",
       "INSTNM                                                                      \n",
       "Alabama A & M University                               0.9741      0.9760   \n",
       "University of Alabama at Birmingham                    0.8805      0.9323   \n",
       "Amridge University                                     0.7251      0.7285   \n",
       "University of Alabama in Huntsville                    0.8625      0.9001   \n",
       "Alabama State University                               0.9487      0.9506   \n",
       "...                                                       ...         ...   \n",
       "SAE Institute of Technology  San Francisco                NaN         NaN   \n",
       "Rasmussen College - Overland Park                         NaN         NaN   \n",
       "National Personal Training Institute of Cleveland         NaN         NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN         NaN   \n",
       "Excel Learning Center-San Antonio South                   NaN         NaN   \n",
       "\n",
       "                                                    UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                     \n",
       "Alabama A & M University                               0.9784     0.9803   \n",
       "University of Alabama at Birmingham                    0.9345     0.9352   \n",
       "Amridge University                                     0.7285     0.7285   \n",
       "University of Alabama in Huntsville                    0.9144     0.9146   \n",
       "Alabama State University                               0.9516     0.9522   \n",
       "...                                                       ...        ...   \n",
       "SAE Institute of Technology  San Francisco                NaN        NaN   \n",
       "Rasmussen College - Overland Park                         NaN        NaN   \n",
       "National Personal Training Institute of Cleveland         NaN        NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN        NaN   \n",
       "Excel Learning Center-San Antonio South                   NaN        NaN   \n",
       "\n",
       "                                                    UGDS_2MOR  UGDS_NRA  \\\n",
       "INSTNM                                                                    \n",
       "Alabama A & M University                               0.9803    0.9862   \n",
       "University of Alabama at Birmingham                    0.9720    0.9899   \n",
       "Amridge University                                     0.7285    0.7285   \n",
       "University of Alabama in Huntsville                    0.9318    0.9650   \n",
       "Alabama State University                               0.9620    0.9863   \n",
       "...                                                       ...       ...   \n",
       "SAE Institute of Technology  San Francisco                NaN       NaN   \n",
       "Rasmussen College - Overland Park                         NaN       NaN   \n",
       "National Personal Training Institute of Cleveland         NaN       NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN       NaN   \n",
       "Excel Learning Center-San Antonio South                   NaN       NaN   \n",
       "\n",
       "                                                    UGDS_UNKN  \n",
       "INSTNM                                                         \n",
       "Alabama A & M University                               1.0000  \n",
       "University of Alabama at Birmingham                    0.9999  \n",
       "Amridge University                                     1.0000  \n",
       "University of Alabama in Huntsville                    1.0000  \n",
       "Alabama State University                               1.0000  \n",
       "...                                                       ...  \n",
       "SAE Institute of Technology  San Francisco                NaN  \n",
       "Rasmussen College - Overland Park                         NaN  \n",
       "National Personal Training Institute of Cleveland         NaN  \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN  \n",
       "Excel Learning Center-San Antonio South                   NaN  \n",
       "\n",
       "[7535 rows x 9 columns]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用累计求和cumsum()可以很容易看到白人、黑人、西班牙裔的比例\n",
    "college_ugds_cumsum = college_ugds_.cumsum(axis=1)\n",
    "college_ugds_cumsum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T06:21:18.150795Z",
     "start_time": "2019-10-28T06:21:18.124862Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>New Beginning College of Cosmetology</th>\n",
       "      <td>0.8957</td>\n",
       "      <td>0.9305</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Virginia University of Lynchburg</th>\n",
       "      <td>0.0120</td>\n",
       "      <td>0.9921</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Turning Point Beauty College</th>\n",
       "      <td>0.1915</td>\n",
       "      <td>0.2341</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>First Coast Barber Academy</th>\n",
       "      <td>0.1667</td>\n",
       "      <td>0.9445</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Poplar Bluff Technical Career Center</th>\n",
       "      <td>0.9362</td>\n",
       "      <td>0.9788</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SAE Institute of Technology  San Francisco</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Rasmussen College - Overland Park</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>National Personal Training Institute of Cleveland</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bay Area Medical Academy - San Jose Satellite Location</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Excel Learning Center-San Antonio South</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>7535 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                    UGDS_WHITE  UGDS_BLACK  \\\n",
       "INSTNM                                                                       \n",
       "New Beginning College of Cosmetology                    0.8957      0.9305   \n",
       "Virginia University of Lynchburg                        0.0120      0.9921   \n",
       "Turning Point Beauty College                            0.1915      0.2341   \n",
       "First Coast Barber Academy                              0.1667      0.9445   \n",
       "Poplar Bluff Technical Career Center                    0.9362      0.9788   \n",
       "...                                                        ...         ...   \n",
       "SAE Institute of Technology  San Francisco                 NaN         NaN   \n",
       "Rasmussen College - Overland Park                          NaN         NaN   \n",
       "National Personal Training Institute of Cleveland          NaN         NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...         NaN         NaN   \n",
       "Excel Learning Center-San Antonio South                    NaN         NaN   \n",
       "\n",
       "                                                    UGDS_HISP  UGDS_ASIAN  \\\n",
       "INSTNM                                                                      \n",
       "New Beginning College of Cosmetology                   1.0001      1.0001   \n",
       "Virginia University of Lynchburg                       1.0001      1.0001   \n",
       "Turning Point Beauty College                           1.0001      1.0001   \n",
       "First Coast Barber Academy                             1.0001      1.0001   \n",
       "Poplar Bluff Technical Career Center                   1.0001      1.0001   \n",
       "...                                                       ...         ...   \n",
       "SAE Institute of Technology  San Francisco                NaN         NaN   \n",
       "Rasmussen College - Overland Park                         NaN         NaN   \n",
       "National Personal Training Institute of Cleveland         NaN         NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN         NaN   \n",
       "Excel Learning Center-San Antonio South                   NaN         NaN   \n",
       "\n",
       "                                                    UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                     \n",
       "New Beginning College of Cosmetology                   1.0001     1.0001   \n",
       "Virginia University of Lynchburg                       1.0001     1.0001   \n",
       "Turning Point Beauty College                           1.0001     1.0001   \n",
       "First Coast Barber Academy                             1.0001     1.0001   \n",
       "Poplar Bluff Technical Career Center                   1.0001     1.0001   \n",
       "...                                                       ...        ...   \n",
       "SAE Institute of Technology  San Francisco                NaN        NaN   \n",
       "Rasmussen College - Overland Park                         NaN        NaN   \n",
       "National Personal Training Institute of Cleveland         NaN        NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN        NaN   \n",
       "Excel Learning Center-San Antonio South                   NaN        NaN   \n",
       "\n",
       "                                                    UGDS_2MOR  UGDS_NRA  \\\n",
       "INSTNM                                                                    \n",
       "New Beginning College of Cosmetology                   1.0001    1.0001   \n",
       "Virginia University of Lynchburg                       1.0001    1.0001   \n",
       "Turning Point Beauty College                           1.0001    1.0001   \n",
       "First Coast Barber Academy                             1.0001    1.0001   \n",
       "Poplar Bluff Technical Career Center                   1.0001    1.0001   \n",
       "...                                                       ...       ...   \n",
       "SAE Institute of Technology  San Francisco                NaN       NaN   \n",
       "Rasmussen College - Overland Park                         NaN       NaN   \n",
       "National Personal Training Institute of Cleveland         NaN       NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN       NaN   \n",
       "Excel Learning Center-San Antonio South                   NaN       NaN   \n",
       "\n",
       "                                                    UGDS_UNKN  \n",
       "INSTNM                                                         \n",
       "New Beginning College of Cosmetology                   1.0001  \n",
       "Virginia University of Lynchburg                       1.0001  \n",
       "Turning Point Beauty College                           1.0001  \n",
       "First Coast Barber Academy                             1.0001  \n",
       "Poplar Bluff Technical Career Center                   1.0001  \n",
       "...                                                       ...  \n",
       "SAE Institute of Technology  San Francisco                NaN  \n",
       "Rasmussen College - Overland Park                         NaN  \n",
       "National Personal Training Institute of Cleveland         NaN  \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN  \n",
       "Excel Learning Center-San Antonio South                   NaN  \n",
       "\n",
       "[7535 rows x 9 columns]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# UGDS_HISP一列降序排列\n",
    "college_ugds_cumsum.sort_values('UGDS_HISP', ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 8.确定大学校园多样性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T07:05:59.053766Z",
     "start_time": "2019-10-28T07:05:59.006891Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Diversity Index</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>School</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Rutgers University--Newark  Newark, NJ</th>\n",
       "      <td>0.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Andrews University  Berrien Springs, MI</th>\n",
       "      <td>0.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stanford University  Stanford, CA</th>\n",
       "      <td>0.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Houston  Houston, TX</th>\n",
       "      <td>0.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Nevada--Las Vegas  Las Vegas, NV</th>\n",
       "      <td>0.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of San Francisco  San Francisco, CA</th>\n",
       "      <td>0.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>San Francisco State University  San Francisco, CA</th>\n",
       "      <td>0.73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Illinois--Chicago  Chicago, IL</th>\n",
       "      <td>0.73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New Jersey Institute of Technology  Newark, NJ</th>\n",
       "      <td>0.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Texas Woman's University  Denton, TX</th>\n",
       "      <td>0.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   Diversity Index\n",
       "School                                                            \n",
       "Rutgers University--Newark  Newark, NJ                        0.76\n",
       "Andrews University  Berrien Springs, MI                       0.74\n",
       "Stanford University  Stanford, CA                             0.74\n",
       "University of Houston  Houston, TX                            0.74\n",
       "University of Nevada--Las Vegas  Las Vegas, NV                0.74\n",
       "University of San Francisco  San Francisco, CA                0.74\n",
       "San Francisco State University  San Francisco, CA             0.73\n",
       "University of Illinois--Chicago  Chicago, IL                  0.73\n",
       "New Jersey Institute of Technology  Newark, NJ                0.72\n",
       "Texas Woman's University  Denton, TX                          0.72"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# US News给出的美国10所最具多样性的大学\n",
    "pd.read_csv('college_diversity.csv', index_col='School')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T07:16:05.285200Z",
     "start_time": "2019-10-28T07:16:05.190457Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.0333</td>\n",
       "      <td>0.9353</td>\n",
       "      <td>0.0055</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0024</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0059</td>\n",
       "      <td>0.0138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.5922</td>\n",
       "      <td>0.2600</td>\n",
       "      <td>0.0283</td>\n",
       "      <td>0.0518</td>\n",
       "      <td>0.0022</td>\n",
       "      <td>0.0007</td>\n",
       "      <td>0.0368</td>\n",
       "      <td>0.0179</td>\n",
       "      <td>0.0100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.2990</td>\n",
       "      <td>0.4192</td>\n",
       "      <td>0.0069</td>\n",
       "      <td>0.0034</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.2715</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.6988</td>\n",
       "      <td>0.1255</td>\n",
       "      <td>0.0382</td>\n",
       "      <td>0.0376</td>\n",
       "      <td>0.0143</td>\n",
       "      <td>0.0002</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.0158</td>\n",
       "      <td>0.9208</td>\n",
       "      <td>0.0121</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0010</td>\n",
       "      <td>0.0006</td>\n",
       "      <td>0.0098</td>\n",
       "      <td>0.0243</td>\n",
       "      <td>0.0137</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                 0.0333      0.9353     0.0055   \n",
       "University of Alabama at Birmingham      0.5922      0.2600     0.0283   \n",
       "Amridge University                       0.2990      0.4192     0.0069   \n",
       "University of Alabama in Huntsville      0.6988      0.1255     0.0382   \n",
       "Alabama State University                 0.0158      0.9208     0.0121   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                 0.0019     0.0024     0.0019   \n",
       "University of Alabama at Birmingham      0.0518     0.0022     0.0007   \n",
       "Amridge University                       0.0034     0.0000     0.0000   \n",
       "University of Alabama in Huntsville      0.0376     0.0143     0.0002   \n",
       "Alabama State University                 0.0019     0.0010     0.0006   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                0.0000    0.0059     0.0138  \n",
       "University of Alabama at Birmingham     0.0368    0.0179     0.0100  \n",
       "Amridge University                      0.0000    0.0000     0.2715  \n",
       "University of Alabama in Huntsville     0.0172    0.0332     0.0350  \n",
       "Alabama State University                0.0098    0.0243     0.0137  "
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college = pd.read_csv('college.csv', index_col='INSTNM')\n",
    "college_ugds_ = college.filter(like='UGDS_')\n",
    "college_ugds_.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T07:18:51.529693Z",
     "start_time": "2019-10-28T07:18:51.515699Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Excel Learning Center-San Antonio South         9\n",
       "Philadelphia College of Osteopathic Medicine    9\n",
       "Assemblies of God Theological Seminary          9\n",
       "Episcopal Divinity School                       9\n",
       "Phillips Graduate Institute                     9\n",
       "dtype: int64"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.isnull().sum(axis=1).sort_values(ascending=False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 如果所有列都是缺失值，则将其去除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T07:22:20.829465Z",
     "start_time": "2019-10-28T07:22:20.811515Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    0\n",
       "UGDS_BLACK    0\n",
       "UGDS_HISP     0\n",
       "UGDS_ASIAN    0\n",
       "UGDS_AIAN     0\n",
       "UGDS_NHPI     0\n",
       "UGDS_2MOR     0\n",
       "UGDS_NRA      0\n",
       "UGDS_UNKN     0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_ = college_ugds_.dropna(how='all')\n",
    "college_ugds_.isnull().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T07:23:22.983044Z",
     "start_time": "2019-10-28T07:23:22.956147Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                  False        True      False   \n",
       "University of Alabama at Birmingham        True        True      False   \n",
       "Amridge University                         True        True      False   \n",
       "University of Alabama in Huntsville        True       False      False   \n",
       "Alabama State University                  False        True      False   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                  False      False      False   \n",
       "University of Alabama at Birmingham       False      False      False   \n",
       "Amridge University                        False      False      False   \n",
       "University of Alabama in Huntsville       False      False      False   \n",
       "Alabama State University                  False      False      False   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                 False     False      False  \n",
       "University of Alabama at Birmingham      False     False      False  \n",
       "Amridge University                       False     False       True  \n",
       "University of Alabama in Huntsville      False     False      False  \n",
       "Alabama State University                 False     False      False  "
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用大于或等于方法ge(),将DataFrame变为布尔值矩阵\n",
    "college_ugds_.ge(.15).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T07:29:32.739766Z",
     "start_time": "2019-10-28T07:29:32.723807Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama A & M University               1\n",
       "University of Alabama at Birmingham    2\n",
       "Amridge University                     3\n",
       "University of Alabama in Huntsville    1\n",
       "Alabama State University               1\n",
       "dtype: int64"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对所有True值求和\n",
    "diversity_metric = college_ugds_.ge(.15).sum(axis='columns')\n",
    "diversity_metric.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T07:30:21.279953Z",
     "start_time": "2019-10-28T07:30:21.269981Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1    3042\n",
       "2    2884\n",
       "3     876\n",
       "4      63\n",
       "0       7\n",
       "5       2\n",
       "dtype: int64"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用value_counts(),查看分布情况\n",
    "diversity_metric.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T07:32:11.686691Z",
     "start_time": "2019-10-28T07:32:11.668738Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    5815\n",
       "UGDS_BLACK    2700\n",
       "UGDS_HISP     2121\n",
       "UGDS_ASIAN     297\n",
       "UGDS_AIAN       94\n",
       "dtype: int64"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diversity_metric1 = college_ugds_.ge(.15).sum(axis='rows')\n",
    "diversity_metric1.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T07:33:12.077423Z",
     "start_time": "2019-10-28T07:33:12.067449Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Regency Beauty Institute-Austin          5\n",
       "Central Texas Beauty College-Temple      5\n",
       "Sullivan and Cogliano Training Center    4\n",
       "Ambria College of Nursing                4\n",
       "Berkeley College-New York                4\n",
       "dtype: int64"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看哪些学校种群比例超过15%的数量多\n",
    "diversity_metric.sort_values(ascending=False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T07:36:37.848143Z",
     "start_time": "2019-10-28T07:36:37.827186Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Regency Beauty Institute-Austin</th>\n",
       "      <td>0.1867</td>\n",
       "      <td>0.2133</td>\n",
       "      <td>0.1600</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.1733</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Central Texas Beauty College-Temple</th>\n",
       "      <td>0.1616</td>\n",
       "      <td>0.2323</td>\n",
       "      <td>0.2626</td>\n",
       "      <td>0.0202</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.1717</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.1515</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Regency Beauty Institute-Austin          0.1867      0.2133     0.1600   \n",
       "Central Texas Beauty College-Temple      0.1616      0.2323     0.2626   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Regency Beauty Institute-Austin          0.0000        0.0        0.0   \n",
       "Central Texas Beauty College-Temple      0.0202        0.0        0.0   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Regency Beauty Institute-Austin         0.1733       0.0     0.2667  \n",
       "Central Texas Beauty College-Temple     0.1717       0.0     0.1515  "
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 用loc()方法查看对应行索引的行\n",
    "college_ugds_.loc[['Regency Beauty Institute-Austin',\n",
    "'Central Texas Beauty College-Temple']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T07:41:02.502364Z",
     "start_time": "2019-10-28T07:41:02.492392Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Rutgers University-Newark         4\n",
       "Andrews University                3\n",
       "Stanford University               3\n",
       "University of Houston             3\n",
       "University of Nevada-Las Vegas    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看US News前五所最具多样性的大学在diversity_metric中的情况\n",
    "us_news_top = ['Rutgers University-Newark',\n",
    "'Andrews University',\n",
    "'Stanford University',\n",
    "'University of Houston',\n",
    "'University of Nevada-Las Vegas']\n",
    "diversity_metric.loc[us_news_top]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 更多"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T07:43:06.349159Z",
     "start_time": "2019-10-28T07:43:06.334199Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Dewey University-Manati                               1.0\n",
       "Yeshiva and Kollel Harbotzas Torah                    1.0\n",
       "Mr Leon's School of Hair Design-Lewiston              1.0\n",
       "Dewey University-Bayamon                              1.0\n",
       "Shepherds Theological Seminary                        1.0\n",
       "Yeshiva Gedolah Kesser Torah                          1.0\n",
       "Monteclaro Escuela de Hoteleria y Artes Culinarias    1.0\n",
       "Yeshiva Shaar Hatorah                                 1.0\n",
       "Bais Medrash Elyon                                    1.0\n",
       "Yeshiva of Nitra Rabbinical College                   1.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 可以用最大种群比例查看那些学校最不具有多样性\n",
    "college_ugds_.max(axis=1).sort_values(ascending=False).head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T07:54:18.538947Z",
     "start_time": "2019-10-28T07:54:18.530972Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    1.0\n",
       "UGDS_BLACK    0.0\n",
       "UGDS_HISP     0.0\n",
       "UGDS_ASIAN    0.0\n",
       "UGDS_AIAN     0.0\n",
       "UGDS_NHPI     0.0\n",
       "UGDS_2MOR     0.0\n",
       "UGDS_NRA      0.0\n",
       "UGDS_UNKN     0.0\n",
       "Name: Talmudical Seminary Oholei Torah, dtype: float64"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看Talmudical Seminary Oholei Torah哲学学校\n",
    "college_ugds_.loc['Talmudical Seminary Oholei Torah']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-28T07:56:25.494430Z",
     "start_time": "2019-10-28T07:56:25.476477Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看是否有学校九个种族的比例都超过了1%\n",
    "(college_ugds_ > .01).all(axis=1).any()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
